|
1
|
|
|
|
|
2
|
|
|
import window from 'window'; |
|
3
|
|
|
import $ from '$'; |
|
4
|
|
|
import _ from '_'; |
|
5
|
|
|
import ko from 'ko'; |
|
6
|
|
|
import {$win, $div, dropdownVisibility, data as GlobalsData} from 'Common/Globals'; |
|
|
|
|
|
|
7
|
|
|
import {ComposeType, EventKeyCode, SaveSettingsStep, FolderType} from 'Common/Enums'; |
|
8
|
|
|
import {Mime} from 'Common/Mime'; |
|
9
|
|
|
import {jassl} from 'Common/Jassl'; |
|
10
|
|
|
|
|
11
|
|
|
import Autolinker from 'Autolinker'; |
|
12
|
|
|
|
|
13
|
|
|
const trim = $.trim; |
|
14
|
|
|
const inArray = $.inArray; |
|
15
|
|
|
const isArray = _.isArray; |
|
16
|
|
|
const isObject = _.isObject; |
|
17
|
|
|
const isFunc = _.isFunction; |
|
18
|
|
|
const isUnd = _.isUndefined; |
|
19
|
|
|
const isNull = _.isNull; |
|
20
|
|
|
const has = _.has; |
|
21
|
|
|
const bind = _.bind; |
|
22
|
|
|
const noop = () => {}; // eslint-disable-line no-empty-function |
|
23
|
|
|
const noopTrue = () => true; |
|
24
|
|
|
const noopFalse = () => false; |
|
25
|
|
|
|
|
26
|
|
|
export {trim, inArray, isArray, isObject, isFunc, isUnd, isNull, has, bind, noop, noopTrue, noopFalse, jassl}; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param {Function} func |
|
30
|
|
|
*/ |
|
31
|
|
|
export function silentTryCatch(func) |
|
|
|
|
|
|
32
|
|
|
{ |
|
33
|
|
|
try { |
|
34
|
|
|
func(); |
|
35
|
|
|
} |
|
36
|
|
|
catch (e) {} // eslint-disable-line no-empty |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param {*} value |
|
41
|
|
|
* @returns {boolean} |
|
42
|
|
|
*/ |
|
43
|
|
|
export function isNormal(value) |
|
|
|
|
|
|
44
|
|
|
{ |
|
45
|
|
|
return !isUnd(value) && !isNull(value); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param {(string|number)} value |
|
50
|
|
|
* @param {boolean=} includeZero = true |
|
51
|
|
|
* @returns {boolean} |
|
52
|
|
|
*/ |
|
53
|
|
|
export function isPosNumeric(value, includeZero = true) |
|
|
|
|
|
|
54
|
|
|
{ |
|
55
|
|
|
return !isNormal(value) ? false : |
|
56
|
|
|
(includeZero ? (/^[0-9]*$/).test(value.toString()) : (/^[1-9]+[0-9]*$/).test(value.toString())); |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param {*} value |
|
61
|
|
|
* @param {number=} defaultValur = 0 |
|
62
|
|
|
* @returns {number} |
|
63
|
|
|
*/ |
|
64
|
|
|
export function pInt(value, defaultValur = 0) |
|
|
|
|
|
|
65
|
|
|
{ |
|
66
|
|
|
const result = isNormal(value) && '' !== value ? window.parseInt(value, 10) : defaultValur; |
|
|
|
|
|
|
67
|
|
|
return window.isNaN(result) ? defaultValur : result; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param {*} value |
|
72
|
|
|
* @returns {string} |
|
73
|
|
|
*/ |
|
74
|
|
|
export function pString(value) |
|
|
|
|
|
|
75
|
|
|
{ |
|
76
|
|
|
return isNormal(value) ? '' + value : ''; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param {*} value |
|
81
|
|
|
* @returns {boolean} |
|
82
|
|
|
*/ |
|
83
|
|
|
export function pBool(value) |
|
|
|
|
|
|
84
|
|
|
{ |
|
85
|
|
|
return !!value; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param {*} value |
|
90
|
|
|
* @returns {string} |
|
91
|
|
|
*/ |
|
92
|
|
|
export function boolToAjax(value) |
|
|
|
|
|
|
93
|
|
|
{ |
|
94
|
|
|
return value ? '1' : '0'; |
|
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param {*} values |
|
99
|
|
|
* @returns {boolean} |
|
100
|
|
|
*/ |
|
101
|
|
|
export function isNonEmptyArray(values) |
|
|
|
|
|
|
102
|
|
|
{ |
|
103
|
|
|
return isArray(values) && 0 < values.length; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @param {string} component |
|
108
|
|
|
* @returns {string} |
|
109
|
|
|
*/ |
|
110
|
|
|
export function encodeURIComponent(component) |
|
|
|
|
|
|
111
|
|
|
{ |
|
112
|
|
|
return window.encodeURIComponent(component); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @param {string} component |
|
117
|
|
|
* @returns {string} |
|
118
|
|
|
*/ |
|
119
|
|
|
export function decodeURIComponent(component) |
|
|
|
|
|
|
120
|
|
|
{ |
|
121
|
|
|
return window.decodeURIComponent(component); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @param {string} url |
|
126
|
|
|
* @returns {string} |
|
127
|
|
|
*/ |
|
128
|
|
|
export function decodeURI(url) |
|
|
|
|
|
|
129
|
|
|
{ |
|
130
|
|
|
return window.decodeURI(url); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @param {string} url |
|
135
|
|
|
* @returns {string} |
|
136
|
|
|
*/ |
|
137
|
|
|
export function encodeURI(url) |
|
|
|
|
|
|
138
|
|
|
{ |
|
139
|
|
|
return window.encodeURI(url); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @param {string} queryString |
|
144
|
|
|
* @returns {Object} |
|
145
|
|
|
*/ |
|
146
|
|
|
export function simpleQueryParser(queryString) |
|
|
|
|
|
|
147
|
|
|
{ |
|
148
|
|
|
let |
|
149
|
|
|
index = 0, |
|
|
|
|
|
|
150
|
|
|
len = 0, |
|
|
|
|
|
|
151
|
|
|
temp = null; |
|
|
|
|
|
|
152
|
|
|
|
|
153
|
|
|
const |
|
154
|
|
|
queries = queryString.split('&'), |
|
|
|
|
|
|
155
|
|
|
params = {}; |
|
|
|
|
|
|
156
|
|
|
|
|
157
|
|
|
for (len = queries.length; index < len; index++) |
|
158
|
|
|
{ |
|
159
|
|
|
temp = queries[index].split('='); |
|
160
|
|
|
params[decodeURIComponent(temp[0])] = decodeURIComponent(temp[1]); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
return params; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @param {number=} len = 32 |
|
168
|
|
|
* @returns {string} |
|
169
|
|
|
*/ |
|
170
|
|
|
export function fakeMd5(len = 32) |
|
|
|
|
|
|
171
|
|
|
{ |
|
172
|
|
|
const |
|
173
|
|
|
line = '0123456789abcdefghijklmnopqrstuvwxyz', |
|
|
|
|
|
|
174
|
|
|
lineLen = line.length; |
|
|
|
|
|
|
175
|
|
|
|
|
176
|
|
|
len = pInt(len); |
|
|
|
|
|
|
177
|
|
|
|
|
178
|
|
|
let result = ''; |
|
|
|
|
|
|
179
|
|
|
while (result.length < len) |
|
180
|
|
|
{ |
|
181
|
|
|
result += line.substr(window.Math.round(window.Math.random() * lineLen), 1); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
return result; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* @param {string} text |
|
189
|
|
|
* @returns {string} |
|
190
|
|
|
*/ |
|
191
|
|
|
export function encodeHtml(text) |
|
|
|
|
|
|
192
|
|
|
{ |
|
193
|
|
|
return isNormal(text) ? _.escape(text.toString()) : ''; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* @param {string} text |
|
198
|
|
|
* @param {number=} len = 100 |
|
199
|
|
|
* @returns {string} |
|
200
|
|
|
*/ |
|
201
|
|
|
export function splitPlainText(text, len = 100) |
|
|
|
|
|
|
202
|
|
|
{ |
|
203
|
|
|
let |
|
204
|
|
|
prefix = '', |
|
|
|
|
|
|
205
|
|
|
subText = '', |
|
|
|
|
|
|
206
|
|
|
result = text, |
|
|
|
|
|
|
207
|
|
|
spacePos = 0, |
|
|
|
|
|
|
208
|
|
|
newLinePos = 0; |
|
|
|
|
|
|
209
|
|
|
|
|
210
|
|
|
while (result.length > len) |
|
211
|
|
|
{ |
|
212
|
|
|
subText = result.substring(0, len); |
|
213
|
|
|
spacePos = subText.lastIndexOf(' '); |
|
214
|
|
|
newLinePos = subText.lastIndexOf('\n'); |
|
215
|
|
|
|
|
216
|
|
|
if (-1 !== newLinePos) |
|
217
|
|
|
{ |
|
218
|
|
|
spacePos = newLinePos; |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
if (-1 === spacePos) |
|
222
|
|
|
{ |
|
223
|
|
|
spacePos = len; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
prefix += subText.substring(0, spacePos) + '\n'; |
|
227
|
|
|
result = result.substring(spacePos + 1); |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
return prefix + result; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
const timeOutAction = (function() { |
|
234
|
|
|
const timeOuts = {}; |
|
235
|
|
|
return (action, fFunction, timeOut) => { |
|
236
|
|
|
timeOuts[action] = isUnd(timeOuts[action]) ? 0 : timeOuts[action]; |
|
237
|
|
|
window.clearTimeout(timeOuts[action]); |
|
238
|
|
|
timeOuts[action] = window.setTimeout(fFunction, timeOut); |
|
239
|
|
|
}; |
|
240
|
|
|
}()); |
|
241
|
|
|
|
|
242
|
|
|
const timeOutActionSecond = (function() { |
|
243
|
|
|
const timeOuts = {}; |
|
244
|
|
|
return (action, fFunction, timeOut) => { |
|
245
|
|
|
if (!timeOuts[action]) |
|
246
|
|
|
{ |
|
247
|
|
|
timeOuts[action] = window.setTimeout(() => { |
|
248
|
|
|
fFunction(); |
|
249
|
|
|
timeOuts[action] = 0; |
|
250
|
|
|
}, timeOut); |
|
251
|
|
|
} |
|
252
|
|
|
}; |
|
253
|
|
|
}()); |
|
254
|
|
|
|
|
255
|
|
|
export {timeOutAction, timeOutActionSecond}; |
|
256
|
|
|
|
|
257
|
|
|
/** |
|
258
|
|
|
* @returns {boolean} |
|
259
|
|
|
*/ |
|
260
|
|
|
export function inFocus() |
|
261
|
|
|
{ |
|
262
|
|
|
try { |
|
263
|
|
|
if (window.document.activeElement) |
|
264
|
|
|
{ |
|
265
|
|
|
if (isUnd(window.document.activeElement.__inFocusCache)) |
|
266
|
|
|
{ |
|
267
|
|
|
window.document.activeElement.__inFocusCache = $(window.document.activeElement).is('input,textarea,iframe,.cke_editable'); |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
return !!window.document.activeElement.__inFocusCache; |
|
271
|
|
|
} |
|
272
|
|
|
} |
|
273
|
|
|
catch (e) {} // eslint-disable-line no-empty |
|
274
|
|
|
|
|
275
|
|
|
return false; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* @param {boolean} force |
|
280
|
|
|
* @returns {void} |
|
281
|
|
|
*/ |
|
282
|
|
|
export function removeInFocus(force) |
|
|
|
|
|
|
283
|
|
|
{ |
|
284
|
|
|
if (window.document && window.document.activeElement && window.document.activeElement.blur) |
|
285
|
|
|
{ |
|
286
|
|
|
try { |
|
287
|
|
|
const activeEl = $(window.document.activeElement); |
|
|
|
|
|
|
288
|
|
|
if (activeEl && activeEl.is('input,textarea')) |
|
|
|
|
|
|
289
|
|
|
{ |
|
290
|
|
|
window.document.activeElement.blur(); |
|
291
|
|
|
} |
|
292
|
|
|
else if (force) |
|
|
|
|
|
|
293
|
|
|
{ |
|
294
|
|
|
window.document.activeElement.blur(); |
|
295
|
|
|
} |
|
296
|
|
|
} |
|
297
|
|
|
catch (e) {} // eslint-disable-line no-empty |
|
298
|
|
|
} |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
/** |
|
302
|
|
|
* @returns {void} |
|
303
|
|
|
*/ |
|
304
|
|
|
export function removeSelection() |
|
305
|
|
|
{ |
|
306
|
|
|
try { |
|
307
|
|
|
if (window && window.getSelection) |
|
308
|
|
|
{ |
|
309
|
|
|
const sel = window.getSelection(); |
|
|
|
|
|
|
310
|
|
|
if (sel && sel.removeAllRanges) |
|
|
|
|
|
|
311
|
|
|
{ |
|
312
|
|
|
sel.removeAllRanges(); |
|
313
|
|
|
} |
|
314
|
|
|
} |
|
315
|
|
|
else if (window.document && window.document.selection && window.document.selection.empty) |
|
316
|
|
|
{ |
|
317
|
|
|
window.document.selection.empty(); |
|
318
|
|
|
} |
|
319
|
|
|
} |
|
320
|
|
|
catch (e) {} // eslint-disable-line no-empty |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
/** |
|
324
|
|
|
* @param {string} prefix |
|
325
|
|
|
* @param {string} subject |
|
326
|
|
|
* @returns {string} |
|
327
|
|
|
*/ |
|
328
|
|
|
export function replySubjectAdd(prefix, subject) |
|
|
|
|
|
|
329
|
|
|
{ |
|
330
|
|
|
prefix = trim(prefix.toUpperCase()); |
|
|
|
|
|
|
331
|
|
|
subject = trim(subject.replace(/[\s]+/g, ' ')); |
|
|
|
|
|
|
332
|
|
|
|
|
333
|
|
|
let drop = false, |
|
|
|
|
|
|
334
|
|
|
re = 'RE' === prefix, |
|
|
|
|
|
|
335
|
|
|
fwd = 'FWD' === prefix; |
|
|
|
|
|
|
336
|
|
|
|
|
337
|
|
|
const |
|
338
|
|
|
parts = [], |
|
|
|
|
|
|
339
|
|
|
prefixIsRe = !fwd; |
|
|
|
|
|
|
340
|
|
|
|
|
341
|
|
|
if ('' !== subject) |
|
342
|
|
|
{ |
|
343
|
|
|
_.each(subject.split(':'), (part) => { |
|
344
|
|
|
const trimmedPart = trim(part); |
|
345
|
|
|
if (!drop && ((/^(RE|FWD)$/i).test(trimmedPart) || (/^(RE|FWD)[\[\(][\d]+[\]\)]$/i).test(trimmedPart))) |
|
|
|
|
|
|
346
|
|
|
{ |
|
347
|
|
|
if (!re) |
|
|
|
|
|
|
348
|
|
|
{ |
|
349
|
|
|
re = !!(/^RE/i).test(trimmedPart); |
|
|
|
|
|
|
350
|
|
|
} |
|
351
|
|
|
|
|
352
|
|
|
if (!fwd) |
|
|
|
|
|
|
353
|
|
|
{ |
|
354
|
|
|
fwd = !!(/^FWD/i).test(trimmedPart); |
|
|
|
|
|
|
355
|
|
|
} |
|
356
|
|
|
} |
|
357
|
|
|
else |
|
358
|
|
|
{ |
|
359
|
|
|
parts.push(part); |
|
360
|
|
|
drop = true; |
|
|
|
|
|
|
361
|
|
|
} |
|
362
|
|
|
}); |
|
363
|
|
|
} |
|
364
|
|
|
|
|
365
|
|
|
if (prefixIsRe) |
|
|
|
|
|
|
366
|
|
|
{ |
|
367
|
|
|
re = false; |
|
368
|
|
|
} |
|
369
|
|
|
else |
|
370
|
|
|
{ |
|
371
|
|
|
fwd = false; |
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
return trim( |
|
375
|
|
|
(prefixIsRe ? 'Re: ' : 'Fwd: ') + |
|
376
|
|
|
(re ? 'Re: ' : '') + |
|
377
|
|
|
(fwd ? 'Fwd: ' : '') + |
|
378
|
|
|
trim(parts.join(':')) |
|
379
|
|
|
); |
|
380
|
|
|
} |
|
381
|
|
|
|
|
382
|
|
|
/** |
|
383
|
|
|
* @param {number} num |
|
384
|
|
|
* @param {number} dec |
|
385
|
|
|
* @returns {number} |
|
386
|
|
|
*/ |
|
387
|
|
|
export function roundNumber(num, dec) |
|
|
|
|
|
|
388
|
|
|
{ |
|
389
|
|
|
return window.Math.round(num * window.Math.pow(10, dec)) / window.Math.pow(10, dec); |
|
390
|
|
|
} |
|
391
|
|
|
|
|
392
|
|
|
/** |
|
393
|
|
|
* @param {(number|string)} sizeInBytes |
|
394
|
|
|
* @returns {string} |
|
395
|
|
|
*/ |
|
396
|
|
|
export function friendlySize(sizeInBytes) |
|
|
|
|
|
|
397
|
|
|
{ |
|
398
|
|
|
sizeInBytes = pInt(sizeInBytes); |
|
|
|
|
|
|
399
|
|
|
|
|
400
|
|
|
switch (true) |
|
401
|
|
|
{ |
|
402
|
|
|
case 1073741824 <= sizeInBytes: |
|
403
|
|
|
return roundNumber(sizeInBytes / 1073741824, 1) + 'GB'; |
|
404
|
|
|
case 1048576 <= sizeInBytes: |
|
405
|
|
|
return roundNumber(sizeInBytes / 1048576, 1) + 'MB'; |
|
406
|
|
|
case 1024 <= sizeInBytes: |
|
407
|
|
|
return roundNumber(sizeInBytes / 1024, 0) + 'KB'; |
|
408
|
|
|
// no default |
|
409
|
|
|
} |
|
410
|
|
|
|
|
411
|
|
|
return sizeInBytes + 'B'; |
|
412
|
|
|
} |
|
413
|
|
|
|
|
414
|
|
|
/** |
|
415
|
|
|
* @param {string} desc |
|
416
|
|
|
*/ |
|
417
|
|
|
export function log(desc) |
|
|
|
|
|
|
418
|
|
|
{ |
|
419
|
|
|
if (window.console && window.console.log) |
|
420
|
|
|
{ |
|
421
|
|
|
window.console.log(desc); |
|
422
|
|
|
} |
|
423
|
|
|
} |
|
424
|
|
|
|
|
425
|
|
|
/** |
|
426
|
|
|
* @param {?} object |
|
427
|
|
|
* @param {string} methodName |
|
428
|
|
|
* @param {Array=} params |
|
429
|
|
|
* @param {number=} delay = 0 |
|
430
|
|
|
*/ |
|
431
|
|
|
export function delegateRun(object, methodName, params, delay = 0) |
|
|
|
|
|
|
432
|
|
|
{ |
|
433
|
|
|
if (object && object[methodName]) |
|
|
|
|
|
|
434
|
|
|
{ |
|
435
|
|
|
delay = pInt(delay); |
|
|
|
|
|
|
436
|
|
|
params = isArray(params) ? params : []; |
|
|
|
|
|
|
437
|
|
|
|
|
438
|
|
|
if (0 >= delay) |
|
439
|
|
|
{ |
|
440
|
|
|
object[methodName](...params); |
|
441
|
|
|
} |
|
442
|
|
|
else |
|
443
|
|
|
{ |
|
444
|
|
|
_.delay(() => { |
|
445
|
|
|
object[methodName](...params); |
|
446
|
|
|
}, delay); |
|
447
|
|
|
} |
|
448
|
|
|
} |
|
449
|
|
|
} |
|
450
|
|
|
|
|
451
|
|
|
/** |
|
452
|
|
|
* @param {?} event |
|
453
|
|
|
*/ |
|
454
|
|
|
export function killCtrlACtrlS(event) |
|
|
|
|
|
|
455
|
|
|
{ |
|
456
|
|
|
event = event || window.event; |
|
|
|
|
|
|
457
|
|
|
if (event && event.ctrlKey && !event.shiftKey && !event.altKey) |
|
458
|
|
|
{ |
|
459
|
|
|
const key = event.keyCode || event.which; |
|
|
|
|
|
|
460
|
|
|
if (key === EventKeyCode.S) |
|
461
|
|
|
{ |
|
462
|
|
|
event.preventDefault(); |
|
463
|
|
|
return; |
|
464
|
|
|
} |
|
465
|
|
|
else if (key === EventKeyCode.A) |
|
466
|
|
|
{ |
|
467
|
|
|
const sender = event.target || event.srcElement; |
|
|
|
|
|
|
468
|
|
|
if (sender && ('true' === '' + sender.contentEditable || |
|
|
|
|
|
|
469
|
|
|
(sender.tagName && sender.tagName.match(/INPUT|TEXTAREA/i)))) |
|
470
|
|
|
{ |
|
471
|
|
|
return; |
|
472
|
|
|
} |
|
473
|
|
|
|
|
474
|
|
|
if (window.getSelection) |
|
475
|
|
|
{ |
|
476
|
|
|
window.getSelection().removeAllRanges(); |
|
477
|
|
|
} |
|
478
|
|
|
else if (window.document.selection && window.document.selection.clear) |
|
479
|
|
|
{ |
|
480
|
|
|
window.document.selection.clear(); |
|
481
|
|
|
} |
|
482
|
|
|
|
|
483
|
|
|
event.preventDefault(); |
|
484
|
|
|
} |
|
485
|
|
|
} |
|
486
|
|
|
} |
|
487
|
|
|
|
|
488
|
|
|
/** |
|
489
|
|
|
* @param {(Object|null|undefined)} context |
|
490
|
|
|
* @param {Function} fExecute |
|
491
|
|
|
* @param {(Function|boolean|null)=} fCanExecute = true |
|
492
|
|
|
* @returns {Function} |
|
493
|
|
|
*/ |
|
494
|
|
|
export function createCommandLegacy(context, fExecute, fCanExecute = true) |
|
|
|
|
|
|
495
|
|
|
{ |
|
496
|
|
|
let fResult = null; |
|
|
|
|
|
|
497
|
|
|
const fNonEmpty = (...args) => { |
|
|
|
|
|
|
498
|
|
|
if (fResult && fResult.canExecute && fResult.canExecute()) |
|
|
|
|
|
|
499
|
|
|
{ |
|
500
|
|
|
fExecute.apply(context, args); |
|
501
|
|
|
} |
|
502
|
|
|
return false; |
|
503
|
|
|
}; |
|
504
|
|
|
|
|
505
|
|
|
fResult = fExecute ? fNonEmpty : noop; |
|
|
|
|
|
|
506
|
|
|
fResult.enabled = ko.observable(true); |
|
507
|
|
|
|
|
508
|
|
|
if (isFunc(fCanExecute)) |
|
509
|
|
|
{ |
|
510
|
|
|
fResult.canExecute = ko.computed(() => fResult.enabled() && fCanExecute.call(context)); |
|
511
|
|
|
} |
|
512
|
|
|
else |
|
513
|
|
|
{ |
|
514
|
|
|
fResult.canExecute = ko.computed(() => fResult.enabled() && !!fCanExecute); |
|
|
|
|
|
|
515
|
|
|
} |
|
516
|
|
|
|
|
517
|
|
|
return fResult; |
|
518
|
|
|
} |
|
519
|
|
|
|
|
520
|
|
|
/** |
|
521
|
|
|
* @param {Function} fExecute |
|
522
|
|
|
* @param {(Function|boolean|null)=} fCanExecute = true |
|
523
|
|
|
* @returns {Function} |
|
524
|
|
|
*/ |
|
525
|
|
|
export function createCommand(fExecute, fCanExecute = true) |
|
|
|
|
|
|
526
|
|
|
{ |
|
527
|
|
|
return createCommandLegacy(null, fExecute, fCanExecute); |
|
528
|
|
|
} |
|
529
|
|
|
|
|
530
|
|
|
/** |
|
531
|
|
|
* @param {string} theme |
|
532
|
|
|
* @returns {string} |
|
533
|
|
|
*/ |
|
534
|
|
|
export const convertThemeName = _.memoize((theme) => { |
|
|
|
|
|
|
535
|
|
|
|
|
536
|
|
|
if ('@custom' === theme.substr(-7)) |
|
537
|
|
|
{ |
|
538
|
|
|
theme = trim(theme.substring(0, theme.length - 7)); |
|
539
|
|
|
} |
|
540
|
|
|
|
|
541
|
|
|
return trim(theme.replace(/[^a-zA-Z0-9]+/g, ' ').replace(/([A-Z])/g, ' $1').replace(/[\s]+/g, ' ')); |
|
542
|
|
|
}); |
|
543
|
|
|
|
|
544
|
|
|
/** |
|
545
|
|
|
* @param {string} name |
|
546
|
|
|
* @returns {string} |
|
547
|
|
|
*/ |
|
548
|
|
|
export function quoteName(name) |
|
|
|
|
|
|
549
|
|
|
{ |
|
550
|
|
|
return name.replace(/["]/g, '\\"'); |
|
551
|
|
|
} |
|
552
|
|
|
|
|
553
|
|
|
/** |
|
554
|
|
|
* @returns {number} |
|
555
|
|
|
*/ |
|
556
|
|
|
export function microtime() |
|
557
|
|
|
{ |
|
558
|
|
|
return (new window.Date()).getTime(); |
|
559
|
|
|
} |
|
560
|
|
|
|
|
561
|
|
|
/** |
|
562
|
|
|
* @returns {number} |
|
563
|
|
|
*/ |
|
564
|
|
|
export function timestamp() |
|
565
|
|
|
{ |
|
566
|
|
|
return window.Math.round(microtime() / 1000); |
|
567
|
|
|
} |
|
568
|
|
|
|
|
569
|
|
|
/** |
|
570
|
|
|
* |
|
571
|
|
|
* @param {string} language |
|
572
|
|
|
* @param {boolean=} isEng = false |
|
573
|
|
|
* @returns {string} |
|
574
|
|
|
*/ |
|
575
|
|
|
export function convertLangName(language, isEng = false) |
|
|
|
|
|
|
576
|
|
|
{ |
|
577
|
|
|
return require('Common/Translator').i18n('LANGS_NAMES' + (true === isEng ? '_EN' : '') + '/LANG_' + |
|
578
|
|
|
language.toUpperCase().replace(/[^a-zA-Z0-9]+/g, '_'), null, language); |
|
579
|
|
|
} |
|
580
|
|
|
|
|
581
|
|
|
/** |
|
582
|
|
|
* @returns {object} |
|
583
|
|
|
*/ |
|
584
|
|
|
export function draggablePlace() |
|
585
|
|
|
{ |
|
586
|
|
|
return $('<div class="draggablePlace">' + |
|
587
|
|
|
'<span class="text"></span> ' + |
|
588
|
|
|
'<i class="icon-copy icon-white visible-on-ctrl"></i>' + |
|
589
|
|
|
'<i class="icon-mail icon-white hidden-on-ctrl"></i>' + |
|
590
|
|
|
'</div>' |
|
591
|
|
|
).appendTo('#rl-hidden'); |
|
592
|
|
|
} |
|
593
|
|
|
|
|
594
|
|
|
/** |
|
595
|
|
|
* @param {object} domOption |
|
|
|
|
|
|
596
|
|
|
* @param {object} item |
|
597
|
|
|
* @returns {void} |
|
598
|
|
|
*/ |
|
599
|
|
|
export function defautOptionsAfterRender(domItem, item) |
|
|
|
|
|
|
600
|
|
|
{ |
|
601
|
|
|
if (item && !isUnd(item.disabled) && domItem) |
|
|
|
|
|
|
602
|
|
|
{ |
|
603
|
|
|
$(domItem) |
|
604
|
|
|
.toggleClass('disabled', item.disabled) |
|
605
|
|
|
.prop('disabled', item.disabled); |
|
606
|
|
|
} |
|
607
|
|
|
} |
|
608
|
|
|
|
|
609
|
|
|
/** |
|
610
|
|
|
* @param {string} title |
|
|
|
|
|
|
611
|
|
|
* @param {Object} body |
|
612
|
|
|
* @param {boolean} isHtml |
|
|
|
|
|
|
613
|
|
|
* @param {boolean} print |
|
|
|
|
|
|
614
|
|
|
*/ |
|
615
|
|
|
export function clearBqSwitcher(body) |
|
|
|
|
|
|
616
|
|
|
{ |
|
617
|
|
|
body.find('blockquote.rl-bq-switcher').removeClass('rl-bq-switcher hidden-bq'); |
|
618
|
|
|
body.find('.rlBlockquoteSwitcher').off('.rlBlockquoteSwitcher').remove(); |
|
619
|
|
|
body.find('[data-html-editor-font-wrapper]').removeAttr('data-html-editor-font-wrapper'); |
|
620
|
|
|
} |
|
621
|
|
|
|
|
622
|
|
|
/** |
|
623
|
|
|
* @param {object} messageData |
|
|
|
|
|
|
624
|
|
|
* @param {Object} body |
|
625
|
|
|
* @param {boolean} isHtml |
|
626
|
|
|
* @param {boolean} print |
|
627
|
|
|
* @returns {void} |
|
628
|
|
|
*/ |
|
629
|
|
|
export function previewMessage({title, subject, date, fromCreds, toCreds, toLabel}, body, isHtml, print) |
|
|
|
|
|
|
630
|
|
|
{ |
|
631
|
|
|
const |
|
632
|
|
|
win = window.open(''), |
|
|
|
|
|
|
633
|
|
|
doc = win.document, |
|
|
|
|
|
|
634
|
|
|
bodyClone = body.clone(), |
|
|
|
|
|
|
635
|
|
|
bodyClass = isHtml ? 'html' : 'plain'; |
|
|
|
|
|
|
636
|
|
|
|
|
637
|
|
|
clearBqSwitcher(bodyClone); |
|
638
|
|
|
|
|
639
|
|
|
const html = bodyClone ? bodyClone.html() : ''; |
|
|
|
|
|
|
640
|
|
|
|
|
641
|
|
|
doc.write(require('Html/PreviewMessage.html') |
|
642
|
|
|
.replace('{{title}}', encodeHtml(title)) |
|
643
|
|
|
.replace('{{subject}}', encodeHtml(subject)) |
|
644
|
|
|
.replace('{{date}}', encodeHtml(date)) |
|
645
|
|
|
.replace('{{fromCreds}}', encodeHtml(fromCreds)) |
|
646
|
|
|
.replace('{{toCreds}}', encodeHtml(toCreds)) |
|
647
|
|
|
.replace('{{toLabel}}', encodeHtml(toLabel)) |
|
648
|
|
|
.replace('{{bodyClass}}', bodyClass) |
|
649
|
|
|
.replace('{{html}}', html) |
|
650
|
|
|
); |
|
651
|
|
|
|
|
652
|
|
|
doc.close(); |
|
653
|
|
|
|
|
654
|
|
|
if (print) |
|
|
|
|
|
|
655
|
|
|
{ |
|
656
|
|
|
window.setTimeout(() => win.print(), 100); |
|
657
|
|
|
} |
|
658
|
|
|
} |
|
659
|
|
|
|
|
660
|
|
|
/** |
|
661
|
|
|
* @param {Function} fCallback |
|
662
|
|
|
* @param {?} koTrigger |
|
663
|
|
|
* @param {?} context = null |
|
664
|
|
|
* @param {number=} timer = 1000 |
|
665
|
|
|
* @returns {Function} |
|
666
|
|
|
*/ |
|
667
|
|
|
export function settingsSaveHelperFunction(fCallback, koTrigger, context = null, timer = 1000) |
|
|
|
|
|
|
668
|
|
|
{ |
|
669
|
|
|
timer = pInt(timer); |
|
|
|
|
|
|
670
|
|
|
return (type, data, cached, requestAction, requestParameters) => { |
|
671
|
|
|
koTrigger.call(context, data && data.Result ? SaveSettingsStep.TrueResult : SaveSettingsStep.FalseResult); |
|
672
|
|
|
if (fCallback) |
|
|
|
|
|
|
673
|
|
|
{ |
|
674
|
|
|
fCallback.call(context, type, data, cached, requestAction, requestParameters); |
|
675
|
|
|
} |
|
676
|
|
|
_.delay(() => { |
|
677
|
|
|
koTrigger.call(context, SaveSettingsStep.Idle); |
|
678
|
|
|
}, timer); |
|
679
|
|
|
}; |
|
680
|
|
|
} |
|
681
|
|
|
|
|
682
|
|
|
/** |
|
683
|
|
|
* @param {object} koTrigger |
|
684
|
|
|
* @param {mixed} context |
|
685
|
|
|
* @returns {mixed} |
|
686
|
|
|
*/ |
|
687
|
|
|
export function settingsSaveHelperSimpleFunction(koTrigger, context) |
|
|
|
|
|
|
688
|
|
|
{ |
|
689
|
|
|
return settingsSaveHelperFunction(null, koTrigger, context, 1000); |
|
690
|
|
|
} |
|
691
|
|
|
|
|
692
|
|
|
/** |
|
693
|
|
|
* @param {object} remote |
|
694
|
|
|
* @param {string} settingName |
|
695
|
|
|
* @param {string} type |
|
696
|
|
|
* @param {function} fTriggerFunction |
|
697
|
|
|
* @returns {function} |
|
698
|
|
|
*/ |
|
699
|
|
|
export function settingsSaveHelperSubscribeFunction(remote, settingName, type, fTriggerFunction) |
|
|
|
|
|
|
700
|
|
|
{ |
|
701
|
|
|
return (value) => { |
|
702
|
|
|
|
|
703
|
|
|
if (remote) |
|
|
|
|
|
|
704
|
|
|
{ |
|
705
|
|
|
switch (type) |
|
706
|
|
|
{ |
|
707
|
|
|
case 'bool': |
|
708
|
|
|
case 'boolean': |
|
709
|
|
|
value = value ? '1' : '0'; |
|
710
|
|
|
break; |
|
711
|
|
|
case 'int': |
|
712
|
|
|
case 'integer': |
|
713
|
|
|
case 'number': |
|
714
|
|
|
value = pInt(value); |
|
715
|
|
|
break; |
|
716
|
|
|
case 'trim': |
|
717
|
|
|
value = trim(value); |
|
718
|
|
|
break; |
|
719
|
|
|
default: |
|
720
|
|
|
value = pString(value); |
|
721
|
|
|
break; |
|
722
|
|
|
} |
|
723
|
|
|
|
|
724
|
|
|
const data = {}; |
|
725
|
|
|
data[settingName] = value; |
|
726
|
|
|
|
|
727
|
|
|
if (remote.saveAdminConfig) |
|
728
|
|
|
{ |
|
729
|
|
|
remote.saveAdminConfig(fTriggerFunction || null, data); |
|
|
|
|
|
|
730
|
|
|
} |
|
731
|
|
|
else if (remote.saveSettings) |
|
732
|
|
|
{ |
|
733
|
|
|
remote.saveSettings(fTriggerFunction || null, data); |
|
734
|
|
|
} |
|
735
|
|
|
} |
|
736
|
|
|
}; |
|
737
|
|
|
} |
|
738
|
|
|
|
|
739
|
|
|
/** |
|
740
|
|
|
* @param {string} html |
|
741
|
|
|
* @returns {string} |
|
742
|
|
|
*/ |
|
743
|
|
|
export function findEmailAndLinks(html) |
|
|
|
|
|
|
744
|
|
|
{ |
|
745
|
|
|
// return html; |
|
746
|
|
|
return Autolinker.link(html, { |
|
747
|
|
|
newWindow: true, |
|
748
|
|
|
stripPrefix: false, |
|
749
|
|
|
urls: true, |
|
750
|
|
|
email: true, |
|
751
|
|
|
twitter: false, |
|
752
|
|
|
phone: false, |
|
753
|
|
|
hashtag: false, |
|
754
|
|
|
replaceFn: function(autolinker, match) { |
|
755
|
|
|
return !(autolinker && match && 'url' === match.getType() && match.matchedText && 0 !== match.matchedText.indexOf('http')); |
|
756
|
|
|
} |
|
757
|
|
|
}); |
|
758
|
|
|
} |
|
759
|
|
|
|
|
760
|
|
|
/** |
|
761
|
|
|
* @param {string} html |
|
762
|
|
|
* @returns {string} |
|
763
|
|
|
*/ |
|
764
|
|
|
export function htmlToPlain(html) |
|
|
|
|
|
|
765
|
|
|
{ |
|
766
|
|
|
let |
|
767
|
|
|
pos = 0, |
|
|
|
|
|
|
768
|
|
|
limit = 0, |
|
|
|
|
|
|
769
|
|
|
iP1 = 0, |
|
|
|
|
|
|
770
|
|
|
iP2 = 0, |
|
|
|
|
|
|
771
|
|
|
iP3 = 0, |
|
|
|
|
|
|
772
|
|
|
|
|
773
|
|
|
text = ''; |
|
|
|
|
|
|
774
|
|
|
|
|
775
|
|
|
const |
|
776
|
|
|
convertBlockquote = (blockquoteText) => { |
|
|
|
|
|
|
777
|
|
|
blockquoteText = '> ' + trim(blockquoteText).replace(/\n/gm, '\n> '); |
|
778
|
|
|
return blockquoteText.replace(/(^|\n)([> ]+)/gm, |
|
779
|
|
|
(...args) => (args && 2 < args.length ? args[1] + trim(args[2].replace(/[\s]/g, '')) + ' ' : '')); |
|
|
|
|
|
|
780
|
|
|
}, |
|
781
|
|
|
convertDivs = (...args) => { |
|
|
|
|
|
|
782
|
|
|
if (args && 1 < args.length) |
|
783
|
|
|
{ |
|
784
|
|
|
let divText = trim(args[1]); |
|
785
|
|
|
if (0 < divText.length) |
|
786
|
|
|
{ |
|
787
|
|
|
divText = divText.replace(/<div[^>]*>([\s\S\r\n]*)<\/div>/gmi, convertDivs); |
|
788
|
|
|
divText = '\n' + trim(divText) + '\n'; |
|
789
|
|
|
} |
|
790
|
|
|
|
|
791
|
|
|
return divText; |
|
792
|
|
|
} |
|
793
|
|
|
|
|
794
|
|
|
return ''; |
|
795
|
|
|
}, |
|
796
|
|
|
convertPre = (...args) => (args && 1 < args.length ? args[1].toString().replace(/[\n]/gm, '<br />').replace(/[\r]/gm, '') : ''), |
|
|
|
|
|
|
797
|
|
|
fixAttibuteValue = (...args) => (args && 1 < args.length ? '' + args[1] + _.escape(args[2]) : ''), |
|
|
|
|
|
|
798
|
|
|
convertLinks = (...args) => (args && 1 < args.length ? trim(args[1]) : ''); |
|
|
|
|
|
|
799
|
|
|
|
|
800
|
|
|
text = html |
|
|
|
|
|
|
801
|
|
|
.replace(/<p[^>]*><\/p>/gi, '') |
|
802
|
|
|
.replace(/<pre[^>]*>([\s\S\r\n\t]*)<\/pre>/gmi, convertPre) |
|
803
|
|
|
.replace(/[\s]+/gm, ' ') |
|
804
|
|
|
.replace(/((?:href|data)\s?=\s?)("[^"]+?"|'[^']+?')/gmi, fixAttibuteValue) |
|
805
|
|
|
.replace(/<br[^>]*>/gmi, '\n') |
|
806
|
|
|
.replace(/<\/h[\d]>/gi, '\n') |
|
807
|
|
|
.replace(/<\/p>/gi, '\n\n') |
|
808
|
|
|
.replace(/<ul[^>]*>/gmi, '\n') |
|
809
|
|
|
.replace(/<\/ul>/gi, '\n') |
|
810
|
|
|
.replace(/<li[^>]*>/gmi, ' * ') |
|
811
|
|
|
.replace(/<\/li>/gi, '\n') |
|
812
|
|
|
.replace(/<\/td>/gi, '\n') |
|
813
|
|
|
.replace(/<\/tr>/gi, '\n') |
|
814
|
|
|
.replace(/<hr[^>]*>/gmi, '\n_______________________________\n\n') |
|
815
|
|
|
.replace(/<div[^>]*>([\s\S\r\n]*)<\/div>/gmi, convertDivs) |
|
816
|
|
|
.replace(/<blockquote[^>]*>/gmi, '\n__bq__start__\n') |
|
817
|
|
|
.replace(/<\/blockquote>/gmi, '\n__bq__end__\n') |
|
818
|
|
|
.replace(/<a [^>]*>([\s\S\r\n]*?)<\/a>/gmi, convertLinks) |
|
819
|
|
|
.replace(/<\/div>/gi, '\n') |
|
820
|
|
|
.replace(/ /gi, ' ') |
|
821
|
|
|
.replace(/"/gi, '"') |
|
822
|
|
|
.replace(/<[^>]*>/gm, ''); |
|
823
|
|
|
|
|
824
|
|
|
text = $div.html(text).text(); |
|
825
|
|
|
|
|
826
|
|
|
text = text |
|
827
|
|
|
.replace(/\n[ \t]+/gm, '\n') |
|
828
|
|
|
.replace(/[\n]{3,}/gm, '\n\n') |
|
829
|
|
|
.replace(/>/gi, '>') |
|
830
|
|
|
.replace(/</gi, '<') |
|
831
|
|
|
.replace(/&/gi, '&'); |
|
832
|
|
|
|
|
833
|
|
|
text = splitPlainText(trim(text)); |
|
834
|
|
|
|
|
835
|
|
|
pos = 0; |
|
|
|
|
|
|
836
|
|
|
limit = 800; |
|
|
|
|
|
|
837
|
|
|
|
|
838
|
|
|
while (0 < limit) |
|
|
|
|
|
|
839
|
|
|
{ |
|
840
|
|
|
limit -= 1; |
|
841
|
|
|
iP1 = text.indexOf('__bq__start__', pos); |
|
|
|
|
|
|
842
|
|
|
if (-1 < iP1) |
|
843
|
|
|
{ |
|
844
|
|
|
iP2 = text.indexOf('__bq__start__', iP1 + 5); |
|
|
|
|
|
|
845
|
|
|
iP3 = text.indexOf('__bq__end__', iP1 + 5); |
|
|
|
|
|
|
846
|
|
|
|
|
847
|
|
|
if ((-1 === iP2 || iP3 < iP2) && iP1 < iP3) |
|
848
|
|
|
{ |
|
849
|
|
|
text = text.substring(0, iP1) + |
|
850
|
|
|
convertBlockquote(text.substring(iP1 + 13, iP3)) + |
|
851
|
|
|
text.substring(iP3 + 11); |
|
852
|
|
|
|
|
853
|
|
|
pos = 0; |
|
854
|
|
|
} |
|
855
|
|
|
else if (-1 < iP2 && iP2 < iP3) |
|
856
|
|
|
{ |
|
857
|
|
|
pos = iP2 - 1; |
|
858
|
|
|
} |
|
859
|
|
|
else |
|
860
|
|
|
{ |
|
861
|
|
|
pos = 0; |
|
862
|
|
|
} |
|
863
|
|
|
} |
|
864
|
|
|
else |
|
865
|
|
|
{ |
|
866
|
|
|
break; |
|
867
|
|
|
} |
|
868
|
|
|
} |
|
869
|
|
|
|
|
870
|
|
|
text = text |
|
871
|
|
|
.replace(/__bq__start__/gm, '') |
|
872
|
|
|
.replace(/__bq__end__/gm, ''); |
|
873
|
|
|
|
|
874
|
|
|
return text; |
|
875
|
|
|
} |
|
876
|
|
|
|
|
877
|
|
|
/** |
|
878
|
|
|
* @param {string} plain |
|
879
|
|
|
* @param {boolean} findEmailAndLinksInText = false |
|
880
|
|
|
* @returns {string} |
|
881
|
|
|
*/ |
|
882
|
|
|
export function plainToHtml(plain, findEmailAndLinksInText = false) |
|
|
|
|
|
|
883
|
|
|
{ |
|
884
|
|
|
plain = plain.toString().replace(/\r/g, ''); |
|
|
|
|
|
|
885
|
|
|
plain = plain.replace(/^>[> ]>+/gm, ([match]) => (match ? match.replace(/[ ]+/g, '') : match)); |
|
|
|
|
|
|
886
|
|
|
|
|
887
|
|
|
let |
|
888
|
|
|
bIn = false, |
|
|
|
|
|
|
889
|
|
|
bDo = true, |
|
|
|
|
|
|
890
|
|
|
bStart = true, |
|
|
|
|
|
|
891
|
|
|
aNextText = [], |
|
|
|
|
|
|
892
|
|
|
sLine = '', |
|
|
|
|
|
|
893
|
|
|
iIndex = 0, |
|
|
|
|
|
|
894
|
|
|
aText = plain.split('\n'); |
|
|
|
|
|
|
895
|
|
|
|
|
896
|
|
|
do |
|
897
|
|
|
{ |
|
898
|
|
|
bDo = false; |
|
899
|
|
|
aNextText = []; |
|
900
|
|
|
for (iIndex = 0; iIndex < aText.length; iIndex++) |
|
901
|
|
|
{ |
|
902
|
|
|
sLine = aText[iIndex]; |
|
903
|
|
|
bStart = '>' === sLine.substr(0, 1); |
|
904
|
|
|
if (bStart && !bIn) |
|
|
|
|
|
|
905
|
|
|
{ |
|
906
|
|
|
bDo = true; |
|
907
|
|
|
bIn = true; |
|
908
|
|
|
aNextText.push('~~~blockquote~~~'); |
|
909
|
|
|
aNextText.push(sLine.substr(1)); |
|
910
|
|
|
} |
|
911
|
|
|
else if (!bStart && bIn) |
|
912
|
|
|
{ |
|
913
|
|
|
if ('' !== sLine) |
|
914
|
|
|
{ |
|
915
|
|
|
bIn = false; |
|
916
|
|
|
aNextText.push('~~~/blockquote~~~'); |
|
917
|
|
|
aNextText.push(sLine); |
|
918
|
|
|
} |
|
919
|
|
|
else |
|
920
|
|
|
{ |
|
921
|
|
|
aNextText.push(sLine); |
|
922
|
|
|
} |
|
923
|
|
|
} |
|
924
|
|
|
else if (bStart && bIn) |
|
925
|
|
|
{ |
|
926
|
|
|
aNextText.push(sLine.substr(1)); |
|
927
|
|
|
} |
|
928
|
|
|
else |
|
929
|
|
|
{ |
|
930
|
|
|
aNextText.push(sLine); |
|
931
|
|
|
} |
|
932
|
|
|
} |
|
933
|
|
|
|
|
934
|
|
|
if (bIn) |
|
935
|
|
|
{ |
|
936
|
|
|
bIn = false; |
|
937
|
|
|
aNextText.push('~~~/blockquote~~~'); |
|
938
|
|
|
} |
|
939
|
|
|
|
|
940
|
|
|
aText = aNextText; |
|
941
|
|
|
} |
|
942
|
|
|
while (bDo); |
|
943
|
|
|
|
|
944
|
|
|
plain = aText.join('\n'); |
|
945
|
|
|
|
|
946
|
|
|
plain = plain |
|
947
|
|
|
// .replace(/~~~\/blockquote~~~\n~~~blockquote~~~/g, '\n') |
|
948
|
|
|
.replace(/&/g, '&') |
|
949
|
|
|
.replace(/>/g, '>').replace(/</g, '<') |
|
950
|
|
|
.replace(/~~~blockquote~~~[\s]*/g, '<blockquote>') |
|
951
|
|
|
.replace(/[\s]*~~~\/blockquote~~~/g, '</blockquote>') |
|
952
|
|
|
.replace(/\n/g, '<br />'); |
|
953
|
|
|
|
|
954
|
|
|
return findEmailAndLinksInText ? findEmailAndLinks(plain) : plain; |
|
|
|
|
|
|
955
|
|
|
} |
|
956
|
|
|
|
|
957
|
|
|
window['rainloop_Utils_htmlToPlain'] = htmlToPlain; // eslint-disable-line dot-notation |
|
958
|
|
|
window['rainloop_Utils_plainToHtml'] = plainToHtml; // eslint-disable-line dot-notation |
|
959
|
|
|
|
|
960
|
|
|
/** |
|
961
|
|
|
* @param {Array} aSystem |
|
962
|
|
|
* @param {Array} aList |
|
963
|
|
|
* @param {Array=} aDisabled |
|
964
|
|
|
* @param {Array=} aHeaderLines |
|
965
|
|
|
* @param {?number=} iUnDeep |
|
966
|
|
|
* @param {Function=} fDisableCallback |
|
967
|
|
|
* @param {Function=} fVisibleCallback |
|
968
|
|
|
* @param {Function=} fRenameCallback |
|
969
|
|
|
* @param {boolean=} bSystem |
|
970
|
|
|
* @param {boolean=} bBuildUnvisible |
|
971
|
|
|
* @returns {Array} |
|
972
|
|
|
*/ |
|
973
|
|
|
export function folderListOptionsBuilder(aSystem, aList, aDisabled, aHeaderLines, |
|
|
|
|
|
|
974
|
|
|
iUnDeep, fDisableCallback, fVisibleCallback, fRenameCallback, bSystem, bBuildUnvisible) |
|
|
|
|
|
|
975
|
|
|
{ |
|
976
|
|
|
let |
|
977
|
|
|
/** |
|
978
|
|
|
* @type {?FolderModel} |
|
979
|
|
|
*/ |
|
980
|
|
|
oItem = null, |
|
|
|
|
|
|
981
|
|
|
bSep = false, |
|
|
|
|
|
|
982
|
|
|
iIndex = 0, |
|
|
|
|
|
|
983
|
|
|
iLen = 0, |
|
|
|
|
|
|
984
|
|
|
aResult = []; |
|
|
|
|
|
|
985
|
|
|
|
|
986
|
|
|
const sDeepPrefix = '\u00A0\u00A0\u00A0'; |
|
|
|
|
|
|
987
|
|
|
|
|
988
|
|
|
bBuildUnvisible = isUnd(bBuildUnvisible) ? false : !!bBuildUnvisible; |
|
|
|
|
|
|
989
|
|
|
bSystem = !isNormal(bSystem) ? 0 < aSystem.length : bSystem; |
|
|
|
|
|
|
990
|
|
|
iUnDeep = !isNormal(iUnDeep) ? 0 : iUnDeep; |
|
|
|
|
|
|
991
|
|
|
fDisableCallback = isNormal(fDisableCallback) ? fDisableCallback : null; |
|
|
|
|
|
|
992
|
|
|
fVisibleCallback = isNormal(fVisibleCallback) ? fVisibleCallback : null; |
|
|
|
|
|
|
993
|
|
|
fRenameCallback = isNormal(fRenameCallback) ? fRenameCallback : null; |
|
|
|
|
|
|
994
|
|
|
|
|
995
|
|
|
if (!isArray(aDisabled)) |
|
996
|
|
|
{ |
|
997
|
|
|
aDisabled = []; |
|
|
|
|
|
|
998
|
|
|
} |
|
999
|
|
|
|
|
1000
|
|
|
if (!isArray(aHeaderLines)) |
|
1001
|
|
|
{ |
|
1002
|
|
|
aHeaderLines = []; |
|
|
|
|
|
|
1003
|
|
|
} |
|
1004
|
|
|
|
|
1005
|
|
|
for (iIndex = 0, iLen = aHeaderLines.length; iIndex < iLen; iIndex++) |
|
1006
|
|
|
{ |
|
1007
|
|
|
aResult.push({ |
|
1008
|
|
|
id: aHeaderLines[iIndex][0], |
|
1009
|
|
|
name: aHeaderLines[iIndex][1], |
|
1010
|
|
|
system: false, |
|
1011
|
|
|
seporator: false, |
|
1012
|
|
|
disabled: false |
|
1013
|
|
|
}); |
|
1014
|
|
|
} |
|
1015
|
|
|
|
|
1016
|
|
|
bSep = true; |
|
1017
|
|
|
for (iIndex = 0, iLen = aSystem.length; iIndex < iLen; iIndex++) |
|
1018
|
|
|
{ |
|
1019
|
|
|
oItem = aSystem[iIndex]; |
|
1020
|
|
|
if (fVisibleCallback ? fVisibleCallback(oItem) : true) |
|
|
|
|
|
|
1021
|
|
|
{ |
|
1022
|
|
|
if (bSep && 0 < aResult.length) |
|
|
|
|
|
|
1023
|
|
|
{ |
|
1024
|
|
|
aResult.push({ |
|
1025
|
|
|
id: '---', |
|
1026
|
|
|
name: '---', |
|
1027
|
|
|
system: false, |
|
1028
|
|
|
seporator: true, |
|
1029
|
|
|
disabled: true |
|
1030
|
|
|
}); |
|
1031
|
|
|
} |
|
1032
|
|
|
|
|
1033
|
|
|
bSep = false; |
|
1034
|
|
|
aResult.push({ |
|
1035
|
|
|
id: oItem.fullNameRaw, |
|
1036
|
|
|
name: fRenameCallback ? fRenameCallback(oItem) : oItem.name(), |
|
|
|
|
|
|
1037
|
|
|
system: true, |
|
1038
|
|
|
seporator: false, |
|
1039
|
|
|
disabled: !oItem.selectable || -1 < inArray(oItem.fullNameRaw, aDisabled) || |
|
1040
|
|
|
(fDisableCallback ? fDisableCallback(oItem) : false) |
|
|
|
|
|
|
1041
|
|
|
}); |
|
1042
|
|
|
} |
|
1043
|
|
|
} |
|
1044
|
|
|
|
|
1045
|
|
|
bSep = true; |
|
1046
|
|
|
for (iIndex = 0, iLen = aList.length; iIndex < iLen; iIndex++) |
|
1047
|
|
|
{ |
|
1048
|
|
|
oItem = aList[iIndex]; |
|
1049
|
|
|
// if (oItem.subScribed() || !oItem.existen || bBuildUnvisible) |
|
1050
|
|
|
if ((oItem.subScribed() || !oItem.existen || bBuildUnvisible) && (oItem.selectable || oItem.hasSubScribedSubfolders())) |
|
|
|
|
|
|
1051
|
|
|
{ |
|
1052
|
|
|
if (fVisibleCallback ? fVisibleCallback(oItem) : true) |
|
1053
|
|
|
{ |
|
1054
|
|
|
if (FolderType.User === oItem.type() || !bSystem || oItem.hasSubScribedSubfolders()) |
|
|
|
|
|
|
1055
|
|
|
{ |
|
1056
|
|
|
if (bSep && 0 < aResult.length) |
|
1057
|
|
|
{ |
|
1058
|
|
|
aResult.push({ |
|
1059
|
|
|
id: '---', |
|
1060
|
|
|
name: '---', |
|
1061
|
|
|
system: false, |
|
1062
|
|
|
seporator: true, |
|
1063
|
|
|
disabled: true |
|
1064
|
|
|
}); |
|
1065
|
|
|
} |
|
1066
|
|
|
|
|
1067
|
|
|
bSep = false; |
|
1068
|
|
|
aResult.push({ |
|
1069
|
|
|
id: oItem.fullNameRaw, |
|
1070
|
|
|
name: (new window.Array(oItem.deep + 1 - iUnDeep)).join(sDeepPrefix) + |
|
1071
|
|
|
(fRenameCallback ? fRenameCallback(oItem) : oItem.name()), |
|
1072
|
|
|
system: false, |
|
1073
|
|
|
seporator: false, |
|
1074
|
|
|
disabled: !oItem.selectable || -1 < inArray(oItem.fullNameRaw, aDisabled) || |
|
1075
|
|
|
(fDisableCallback ? fDisableCallback(oItem) : false) |
|
1076
|
|
|
}); |
|
1077
|
|
|
} |
|
1078
|
|
|
} |
|
1079
|
|
|
} |
|
1080
|
|
|
|
|
1081
|
|
|
if (oItem.subScribed() && 0 < oItem.subFolders().length) |
|
1082
|
|
|
{ |
|
1083
|
|
|
aResult = aResult.concat(folderListOptionsBuilder([], oItem.subFolders(), aDisabled, [], |
|
1084
|
|
|
iUnDeep, fDisableCallback, fVisibleCallback, fRenameCallback, bSystem, bBuildUnvisible)); |
|
1085
|
|
|
} |
|
1086
|
|
|
} |
|
1087
|
|
|
|
|
1088
|
|
|
return aResult; |
|
1089
|
|
|
} |
|
1090
|
|
|
|
|
1091
|
|
|
/** |
|
1092
|
|
|
* @param {object} element |
|
1093
|
|
|
* @returns {void} |
|
1094
|
|
|
*/ |
|
1095
|
|
|
export function selectElement(element) |
|
|
|
|
|
|
1096
|
|
|
{ |
|
1097
|
|
|
let |
|
1098
|
|
|
sel = null, |
|
|
|
|
|
|
1099
|
|
|
range = null; |
|
|
|
|
|
|
1100
|
|
|
|
|
1101
|
|
|
if (window.getSelection) |
|
1102
|
|
|
{ |
|
1103
|
|
|
sel = window.getSelection(); |
|
1104
|
|
|
sel.removeAllRanges(); |
|
1105
|
|
|
range = window.document.createRange(); |
|
1106
|
|
|
range.selectNodeContents(element); |
|
1107
|
|
|
sel.addRange(range); |
|
1108
|
|
|
} |
|
1109
|
|
|
else if (window.document.selection) |
|
1110
|
|
|
{ |
|
1111
|
|
|
range = window.document.body.createTextRange(); |
|
1112
|
|
|
range.moveToElementText(element); |
|
1113
|
|
|
range.select(); |
|
1114
|
|
|
} |
|
1115
|
|
|
} |
|
1116
|
|
|
|
|
1117
|
|
|
export const detectDropdownVisibility = _.debounce(() => { |
|
|
|
|
|
|
1118
|
|
|
dropdownVisibility(!!_.find(GlobalsData.aBootstrapDropdowns, (item) => item.hasClass('open'))); |
|
1119
|
|
|
}, 50); |
|
1120
|
|
|
|
|
1121
|
|
|
/** |
|
1122
|
|
|
* @param {boolean=} delay = false |
|
1123
|
|
|
*/ |
|
1124
|
|
|
export function triggerAutocompleteInputChange(delay = false) { |
|
|
|
|
|
|
1125
|
|
|
|
|
1126
|
|
|
const fFunc = () => { |
|
|
|
|
|
|
1127
|
|
|
$('.checkAutocomplete').trigger('change'); |
|
1128
|
|
|
}; |
|
1129
|
|
|
|
|
1130
|
|
|
if (delay) |
|
|
|
|
|
|
1131
|
|
|
{ |
|
1132
|
|
|
_.delay(fFunc, 100); |
|
1133
|
|
|
} |
|
1134
|
|
|
else |
|
1135
|
|
|
{ |
|
1136
|
|
|
fFunc(); |
|
1137
|
|
|
} |
|
1138
|
|
|
} |
|
1139
|
|
|
|
|
1140
|
|
|
const configurationScriptTagCache = {}; |
|
|
|
|
|
|
1141
|
|
|
|
|
1142
|
|
|
/** |
|
1143
|
|
|
* @param {string} configuration |
|
1144
|
|
|
* @returns {object} |
|
1145
|
|
|
*/ |
|
1146
|
|
|
export function getConfigurationFromScriptTag(configuration) |
|
|
|
|
|
|
1147
|
|
|
{ |
|
1148
|
|
|
if (!configurationScriptTagCache[configuration]) |
|
1149
|
|
|
{ |
|
1150
|
|
|
configurationScriptTagCache[configuration] = $('script[type="application/json"][data-configuration="' + configuration + '"]'); |
|
1151
|
|
|
} |
|
1152
|
|
|
|
|
1153
|
|
|
try |
|
1154
|
|
|
{ |
|
1155
|
|
|
return JSON.parse(configurationScriptTagCache[configuration].text()); |
|
1156
|
|
|
} |
|
1157
|
|
|
catch (e) {} // eslint-disable-line no-empty |
|
1158
|
|
|
|
|
1159
|
|
|
return {}; |
|
1160
|
|
|
} |
|
1161
|
|
|
|
|
1162
|
|
|
/** |
|
1163
|
|
|
* @param {mixed} mPropOrValue |
|
|
|
|
|
|
1164
|
|
|
* @param {mixed} value |
|
1165
|
|
|
*/ |
|
1166
|
|
|
export function disposeOne(propOrValue, value) |
|
|
|
|
|
|
1167
|
|
|
{ |
|
1168
|
|
|
const disposable = value || propOrValue; |
|
|
|
|
|
|
1169
|
|
|
if (disposable && 'function' === typeof disposable.dispose) |
|
|
|
|
|
|
1170
|
|
|
{ |
|
1171
|
|
|
disposable.dispose(); |
|
1172
|
|
|
} |
|
1173
|
|
|
} |
|
1174
|
|
|
|
|
1175
|
|
|
/** |
|
1176
|
|
|
* @param {Object} object |
|
1177
|
|
|
*/ |
|
1178
|
|
|
export function disposeObject(object) |
|
|
|
|
|
|
1179
|
|
|
{ |
|
1180
|
|
|
if (object) |
|
|
|
|
|
|
1181
|
|
|
{ |
|
1182
|
|
|
if (isArray(object.disposables)) |
|
1183
|
|
|
{ |
|
1184
|
|
|
_.each(object.disposables, disposeOne); |
|
1185
|
|
|
} |
|
1186
|
|
|
|
|
1187
|
|
|
ko.utils.objectForEach(object, disposeOne); |
|
1188
|
|
|
} |
|
1189
|
|
|
} |
|
1190
|
|
|
|
|
1191
|
|
|
/** |
|
1192
|
|
|
* @param {Object|Array} objectOrObjects |
|
1193
|
|
|
* @returns {void} |
|
1194
|
|
|
*/ |
|
1195
|
|
|
export function delegateRunOnDestroy(objectOrObjects) |
|
|
|
|
|
|
1196
|
|
|
{ |
|
1197
|
|
|
if (objectOrObjects) |
|
|
|
|
|
|
1198
|
|
|
{ |
|
1199
|
|
|
if (isArray(objectOrObjects)) |
|
1200
|
|
|
{ |
|
1201
|
|
|
_.each(objectOrObjects, (item) => { |
|
1202
|
|
|
delegateRunOnDestroy(item); |
|
1203
|
|
|
}); |
|
1204
|
|
|
} |
|
1205
|
|
|
else if (objectOrObjects && objectOrObjects.onDestroy) |
|
|
|
|
|
|
1206
|
|
|
{ |
|
1207
|
|
|
objectOrObjects.onDestroy(); |
|
1208
|
|
|
} |
|
1209
|
|
|
} |
|
1210
|
|
|
} |
|
1211
|
|
|
|
|
1212
|
|
|
/** |
|
1213
|
|
|
* @param {object} $styleTag |
|
1214
|
|
|
* @param {string} css |
|
1215
|
|
|
* @returns {boolean} |
|
1216
|
|
|
*/ |
|
1217
|
|
|
export function appendStyles($styleTag, css) |
|
|
|
|
|
|
1218
|
|
|
{ |
|
1219
|
|
|
if ($styleTag && $styleTag[0]) |
|
|
|
|
|
|
1220
|
|
|
{ |
|
1221
|
|
|
if ($styleTag[0].styleSheet && !isUnd($styleTag[0].styleSheet.cssText)) |
|
1222
|
|
|
{ |
|
1223
|
|
|
$styleTag[0].styleSheet.cssText = css; |
|
1224
|
|
|
} |
|
1225
|
|
|
else |
|
1226
|
|
|
{ |
|
1227
|
|
|
$styleTag.text(css); |
|
1228
|
|
|
} |
|
1229
|
|
|
|
|
1230
|
|
|
return true; |
|
1231
|
|
|
} |
|
1232
|
|
|
|
|
1233
|
|
|
return false; |
|
1234
|
|
|
} |
|
1235
|
|
|
|
|
1236
|
|
|
let |
|
1237
|
|
|
__themeTimer = 0, |
|
|
|
|
|
|
1238
|
|
|
__themeAjax = null; |
|
|
|
|
|
|
1239
|
|
|
|
|
1240
|
|
|
/** |
|
1241
|
|
|
* @param {string} value |
|
1242
|
|
|
* @param {function=} themeTrigger = noop |
|
1243
|
|
|
* @returns {void} |
|
1244
|
|
|
*/ |
|
1245
|
|
|
export function changeTheme(value, themeTrigger = noop) |
|
|
|
|
|
|
1246
|
|
|
{ |
|
1247
|
|
|
const |
|
1248
|
|
|
themeLink = $('#app-theme-link'), |
|
|
|
|
|
|
1249
|
|
|
clearTimer = () => { |
|
|
|
|
|
|
1250
|
|
|
__themeTimer = window.setTimeout(() => themeTrigger(SaveSettingsStep.Idle), 1000); |
|
|
|
|
|
|
1251
|
|
|
__themeAjax = null; |
|
|
|
|
|
|
1252
|
|
|
}; |
|
1253
|
|
|
|
|
1254
|
|
|
let |
|
1255
|
|
|
themeStyle = $('#app-theme-style'), |
|
|
|
|
|
|
1256
|
|
|
url = themeLink.attr('href'); |
|
|
|
|
|
|
1257
|
|
|
|
|
1258
|
|
|
if (!url) |
|
|
|
|
|
|
1259
|
|
|
{ |
|
1260
|
|
|
url = themeStyle.attr('data-href'); |
|
1261
|
|
|
} |
|
1262
|
|
|
|
|
1263
|
|
|
if (url) |
|
1264
|
|
|
{ |
|
1265
|
|
|
url = url.toString().replace(/\/-\/[^\/]+\/\-\//, '/-/' + value + '/-/'); |
|
1266
|
|
|
url = url.toString().replace(/\/Css\/[^\/]+\/User\//, '/Css/0/User/'); |
|
1267
|
|
|
url = url.toString().replace(/\/Hash\/[^\/]+\//, '/Hash/-/'); |
|
1268
|
|
|
|
|
1269
|
|
|
if ('Json/' !== url.substring(url.length - 5, url.length)) |
|
1270
|
|
|
{ |
|
1271
|
|
|
url += 'Json/'; |
|
1272
|
|
|
} |
|
1273
|
|
|
|
|
1274
|
|
|
window.clearTimeout(__themeTimer); |
|
1275
|
|
|
|
|
1276
|
|
|
themeTrigger(SaveSettingsStep.Animate); |
|
1277
|
|
|
|
|
1278
|
|
|
if (__themeAjax && __themeAjax.abort) |
|
|
|
|
|
|
1279
|
|
|
{ |
|
1280
|
|
|
__themeAjax.abort(); |
|
1281
|
|
|
} |
|
1282
|
|
|
|
|
1283
|
|
|
__themeAjax = $.ajax({ |
|
|
|
|
|
|
1284
|
|
|
url: url, |
|
1285
|
|
|
dataType: 'json' |
|
1286
|
|
|
}).then((data) => { |
|
1287
|
|
|
|
|
1288
|
|
|
if (data && isArray(data) && 2 === data.length) |
|
1289
|
|
|
{ |
|
1290
|
|
|
if (themeLink && themeLink[0] && (!themeStyle || !themeStyle[0])) |
|
|
|
|
|
|
1291
|
|
|
{ |
|
1292
|
|
|
themeStyle = $('<style id="app-theme-style"></style>'); |
|
|
|
|
|
|
1293
|
|
|
themeLink.after(themeStyle); |
|
1294
|
|
|
themeLink.remove(); |
|
1295
|
|
|
} |
|
1296
|
|
|
|
|
1297
|
|
|
if (themeStyle && themeStyle[0]) |
|
1298
|
|
|
{ |
|
1299
|
|
|
if (appendStyles(themeStyle, data[1])) |
|
1300
|
|
|
{ |
|
1301
|
|
|
themeStyle.attr('data-href', url).attr('data-theme', data[0]); |
|
1302
|
|
|
} |
|
1303
|
|
|
} |
|
1304
|
|
|
|
|
1305
|
|
|
themeTrigger(SaveSettingsStep.TrueResult); |
|
1306
|
|
|
} |
|
1307
|
|
|
|
|
1308
|
|
|
}).then(clearTimer, clearTimer); |
|
1309
|
|
|
} |
|
1310
|
|
|
} |
|
1311
|
|
|
|
|
1312
|
|
|
/** |
|
1313
|
|
|
* @returns {function} |
|
1314
|
|
|
*/ |
|
1315
|
|
|
export function computedPagenatorHelper(koCurrentPage, koPageCount) |
|
|
|
|
|
|
1316
|
|
|
{ |
|
1317
|
|
|
return () => { |
|
1318
|
|
|
|
|
1319
|
|
|
const |
|
1320
|
|
|
currentPage = koCurrentPage(), |
|
1321
|
|
|
pageCount = koPageCount(), |
|
1322
|
|
|
result = [], |
|
1323
|
|
|
fAdd = (index, push = true, customName = '') => { |
|
1324
|
|
|
|
|
1325
|
|
|
const data = { |
|
1326
|
|
|
current: index === currentPage, |
|
1327
|
|
|
name: '' === customName ? index.toString() : customName.toString(), |
|
1328
|
|
|
custom: '' !== customName, |
|
1329
|
|
|
title: '' === customName ? '' : index.toString(), |
|
1330
|
|
|
value: index.toString() |
|
1331
|
|
|
}; |
|
1332
|
|
|
|
|
1333
|
|
|
if (push) |
|
1334
|
|
|
{ |
|
1335
|
|
|
result.push(data); |
|
1336
|
|
|
} |
|
1337
|
|
|
else |
|
1338
|
|
|
{ |
|
1339
|
|
|
result.unshift(data); |
|
1340
|
|
|
} |
|
1341
|
|
|
}; |
|
1342
|
|
|
|
|
1343
|
|
|
let |
|
1344
|
|
|
prev = 0, |
|
1345
|
|
|
next = 0, |
|
1346
|
|
|
limit = 2; |
|
1347
|
|
|
|
|
1348
|
|
|
if (1 < pageCount || (0 < pageCount && pageCount < currentPage)) |
|
1349
|
|
|
{ |
|
1350
|
|
|
if (pageCount < currentPage) |
|
1351
|
|
|
{ |
|
1352
|
|
|
fAdd(pageCount); |
|
1353
|
|
|
prev = pageCount; |
|
1354
|
|
|
next = pageCount; |
|
1355
|
|
|
} |
|
1356
|
|
|
else |
|
1357
|
|
|
{ |
|
1358
|
|
|
if (3 >= currentPage || pageCount - 2 <= currentPage) |
|
1359
|
|
|
{ |
|
1360
|
|
|
limit += 2; |
|
1361
|
|
|
} |
|
1362
|
|
|
|
|
1363
|
|
|
fAdd(currentPage); |
|
1364
|
|
|
prev = currentPage; |
|
1365
|
|
|
next = currentPage; |
|
1366
|
|
|
} |
|
1367
|
|
|
|
|
1368
|
|
|
while (0 < limit) { |
|
1369
|
|
|
|
|
1370
|
|
|
prev -= 1; |
|
1371
|
|
|
next += 1; |
|
1372
|
|
|
|
|
1373
|
|
|
if (0 < prev) |
|
1374
|
|
|
{ |
|
1375
|
|
|
fAdd(prev, false); |
|
1376
|
|
|
limit -= 1; |
|
1377
|
|
|
} |
|
1378
|
|
|
|
|
1379
|
|
|
if (pageCount >= next) |
|
1380
|
|
|
{ |
|
1381
|
|
|
fAdd(next, true); |
|
1382
|
|
|
limit -= 1; |
|
1383
|
|
|
} |
|
1384
|
|
|
else if (0 >= prev) |
|
1385
|
|
|
{ |
|
1386
|
|
|
break; |
|
1387
|
|
|
} |
|
1388
|
|
|
} |
|
1389
|
|
|
|
|
1390
|
|
|
if (3 === prev) |
|
1391
|
|
|
{ |
|
1392
|
|
|
fAdd(2, false); |
|
1393
|
|
|
} |
|
1394
|
|
|
else if (3 < prev) |
|
1395
|
|
|
{ |
|
1396
|
|
|
fAdd(Math.round((prev - 1) / 2), false, '...'); |
|
1397
|
|
|
} |
|
1398
|
|
|
|
|
1399
|
|
|
if (pageCount - 2 === next) |
|
1400
|
|
|
{ |
|
1401
|
|
|
fAdd(pageCount - 1, true); |
|
1402
|
|
|
} |
|
1403
|
|
|
else if (pageCount - 2 > next) |
|
1404
|
|
|
{ |
|
1405
|
|
|
fAdd(Math.round((pageCount + next) / 2), true, '...'); |
|
1406
|
|
|
} |
|
1407
|
|
|
|
|
1408
|
|
|
// first and last |
|
1409
|
|
|
if (1 < prev) |
|
1410
|
|
|
{ |
|
1411
|
|
|
fAdd(1, false); |
|
1412
|
|
|
} |
|
1413
|
|
|
|
|
1414
|
|
|
if (pageCount > next) |
|
1415
|
|
|
{ |
|
1416
|
|
|
fAdd(pageCount, true); |
|
1417
|
|
|
} |
|
1418
|
|
|
} |
|
1419
|
|
|
|
|
1420
|
|
|
return result; |
|
1421
|
|
|
}; |
|
1422
|
|
|
} |
|
1423
|
|
|
|
|
1424
|
|
|
/** |
|
1425
|
|
|
* @param {string} fileName |
|
1426
|
|
|
* @returns {string} |
|
1427
|
|
|
*/ |
|
1428
|
|
|
export function getFileExtension(fileName) |
|
|
|
|
|
|
1429
|
|
|
{ |
|
1430
|
|
|
fileName = trim(fileName).toLowerCase(); |
|
|
|
|
|
|
1431
|
|
|
|
|
1432
|
|
|
const result = fileName.split('.').pop(); |
|
|
|
|
|
|
1433
|
|
|
return result === fileName ? '' : result; |
|
1434
|
|
|
} |
|
1435
|
|
|
|
|
1436
|
|
|
/** |
|
1437
|
|
|
* @param {string} fileName |
|
1438
|
|
|
* @returns {string} |
|
1439
|
|
|
*/ |
|
1440
|
|
|
export function mimeContentType(fileName) |
|
|
|
|
|
|
1441
|
|
|
{ |
|
1442
|
|
|
let |
|
1443
|
|
|
ext = '', |
|
|
|
|
|
|
1444
|
|
|
result = 'application/octet-stream'; |
|
|
|
|
|
|
1445
|
|
|
|
|
1446
|
|
|
fileName = trim(fileName).toLowerCase(); |
|
|
|
|
|
|
1447
|
|
|
|
|
1448
|
|
|
if ('winmail.dat' === fileName) |
|
1449
|
|
|
{ |
|
1450
|
|
|
return 'application/ms-tnef'; |
|
1451
|
|
|
} |
|
1452
|
|
|
|
|
1453
|
|
|
ext = getFileExtension(fileName); |
|
1454
|
|
|
if (ext && 0 < ext.length && !isUnd(Mime[ext])) |
|
|
|
|
|
|
1455
|
|
|
{ |
|
1456
|
|
|
result = Mime[ext]; |
|
1457
|
|
|
} |
|
1458
|
|
|
|
|
1459
|
|
|
return result; |
|
1460
|
|
|
} |
|
1461
|
|
|
|
|
1462
|
|
|
/** |
|
1463
|
|
|
* @param {string} url |
|
1464
|
|
|
* @param {number} value |
|
1465
|
|
|
* @param {Function} fCallback |
|
1466
|
|
|
*/ |
|
1467
|
|
|
export function resizeAndCrop(url, value, fCallback) |
|
|
|
|
|
|
1468
|
|
|
{ |
|
1469
|
|
|
const img = new window.Image(); |
|
|
|
|
|
|
1470
|
|
|
img.onload = function() { |
|
1471
|
|
|
|
|
1472
|
|
|
let |
|
1473
|
|
|
diff = [0, 0]; |
|
|
|
|
|
|
1474
|
|
|
|
|
1475
|
|
|
const |
|
1476
|
|
|
canvas = window.document.createElement('canvas'), |
|
1477
|
|
|
ctx = canvas.getContext('2d'); |
|
1478
|
|
|
|
|
1479
|
|
|
canvas.width = value; |
|
1480
|
|
|
canvas.height = value; |
|
1481
|
|
|
|
|
1482
|
|
|
if (this.width > this.height) |
|
1483
|
|
|
{ |
|
1484
|
|
|
diff = [this.width - this.height, 0]; |
|
1485
|
|
|
} |
|
1486
|
|
|
else |
|
1487
|
|
|
{ |
|
1488
|
|
|
diff = [0, this.height - this.width]; |
|
1489
|
|
|
} |
|
1490
|
|
|
|
|
1491
|
|
|
ctx.fillStyle = '#fff'; |
|
1492
|
|
|
ctx.fillRect(0, 0, value, value); |
|
1493
|
|
|
ctx.drawImage(this, diff[0] / 2, diff[1] / 2, this.width - diff[0], this.height - diff[1], 0, 0, value, value); |
|
1494
|
|
|
|
|
1495
|
|
|
fCallback(canvas.toDataURL('image/jpeg')); |
|
1496
|
|
|
}; |
|
1497
|
|
|
|
|
1498
|
|
|
img.src = url; |
|
1499
|
|
|
} |
|
1500
|
|
|
|
|
1501
|
|
|
/** |
|
1502
|
|
|
* @param {string} mailToUrl |
|
1503
|
|
|
* @param {Function} PopupComposeVoreModel |
|
1504
|
|
|
* @returns {boolean} |
|
1505
|
|
|
*/ |
|
1506
|
|
|
export function mailToHelper(mailToUrl, PopupComposeVoreModel) |
|
|
|
|
|
|
1507
|
|
|
{ |
|
1508
|
|
|
if (mailToUrl && 'mailto:' === mailToUrl.toString().substr(0, 7).toLowerCase()) |
|
|
|
|
|
|
1509
|
|
|
{ |
|
1510
|
|
|
if (!PopupComposeVoreModel) |
|
|
|
|
|
|
1511
|
|
|
{ |
|
1512
|
|
|
return true; |
|
1513
|
|
|
} |
|
1514
|
|
|
|
|
1515
|
|
|
mailToUrl = mailToUrl.toString().substr(7); |
|
|
|
|
|
|
1516
|
|
|
|
|
1517
|
|
|
let |
|
1518
|
|
|
to = [], |
|
|
|
|
|
|
1519
|
|
|
cc = null, |
|
|
|
|
|
|
1520
|
|
|
bcc = null, |
|
|
|
|
|
|
1521
|
|
|
params = {}; |
|
|
|
|
|
|
1522
|
|
|
|
|
1523
|
|
|
const |
|
1524
|
|
|
email = mailToUrl.replace(/\?.+$/, ''), |
|
|
|
|
|
|
1525
|
|
|
query = mailToUrl.replace(/^[^\?]*\?/, ''), |
|
|
|
|
|
|
1526
|
|
|
EmailModel = require('Model/Email').default, |
|
|
|
|
|
|
1527
|
|
|
emailObj = new EmailModel(), |
|
|
|
|
|
|
1528
|
|
|
fParseEmailLine = (line) => (line ? _.compact(_.map(decodeURIComponent(line).split(/[,]/), (item) => { |
|
|
|
|
|
|
1529
|
|
|
emailObj.clear(); |
|
1530
|
|
|
emailObj.mailsoParse(item); |
|
1531
|
|
|
return '' !== emailObj.email ? emailObj : null; |
|
1532
|
|
|
})) : null); |
|
1533
|
|
|
|
|
1534
|
|
|
to = fParseEmailLine(email); |
|
|
|
|
|
|
1535
|
|
|
params = simpleQueryParser(query); |
|
|
|
|
|
|
1536
|
|
|
|
|
1537
|
|
|
if (!isUnd(params.cc)) |
|
1538
|
|
|
{ |
|
1539
|
|
|
cc = fParseEmailLine(decodeURIComponent(params.cc)); |
|
|
|
|
|
|
1540
|
|
|
} |
|
1541
|
|
|
|
|
1542
|
|
|
if (!isUnd(params.bcc)) |
|
1543
|
|
|
{ |
|
1544
|
|
|
bcc = fParseEmailLine(decodeURIComponent(params.bcc)); |
|
|
|
|
|
|
1545
|
|
|
} |
|
1546
|
|
|
|
|
1547
|
|
|
require('Knoin/Knoin').showScreenPopup(PopupComposeVoreModel, [ |
|
1548
|
|
|
ComposeType.Empty, null, to, cc, bcc, |
|
1549
|
|
|
isUnd(params.subject) ? null : pString(decodeURIComponent(params.subject)), |
|
1550
|
|
|
isUnd(params.body) ? null : plainToHtml(pString(decodeURIComponent(params.body))) |
|
1551
|
|
|
]); |
|
1552
|
|
|
|
|
1553
|
|
|
return true; |
|
1554
|
|
|
} |
|
1555
|
|
|
|
|
1556
|
|
|
return false; |
|
1557
|
|
|
} |
|
1558
|
|
|
|
|
1559
|
|
|
/** |
|
1560
|
|
|
* @param {Function} fn |
|
1561
|
|
|
* @returns {void} |
|
1562
|
|
|
*/ |
|
1563
|
|
|
export function domReady(fn) |
|
|
|
|
|
|
1564
|
|
|
{ |
|
1565
|
|
|
$(() => fn()); |
|
1566
|
|
|
// |
|
1567
|
|
|
// if ('loading' !== window.document.readyState) |
|
1568
|
|
|
// { |
|
1569
|
|
|
// fn(); |
|
1570
|
|
|
// } |
|
1571
|
|
|
// else |
|
1572
|
|
|
// { |
|
1573
|
|
|
// window.document.addEventListener('DOMContentLoaded', fn); |
|
1574
|
|
|
// } |
|
1575
|
|
|
} |
|
1576
|
|
|
|
|
1577
|
|
|
export const windowResize = _.debounce((timeout) => { |
|
|
|
|
|
|
1578
|
|
|
if (isUnd(timeout) || isNull(timeout)) |
|
1579
|
|
|
{ |
|
1580
|
|
|
$win.resize(); |
|
1581
|
|
|
} |
|
1582
|
|
|
else |
|
1583
|
|
|
{ |
|
1584
|
|
|
window.setTimeout(() => { |
|
1585
|
|
|
$win.resize(); |
|
1586
|
|
|
}, timeout); |
|
1587
|
|
|
} |
|
1588
|
|
|
}, 50); |
|
1589
|
|
|
|
|
1590
|
|
|
/** |
|
1591
|
|
|
* @returns {void} |
|
1592
|
|
|
*/ |
|
1593
|
|
|
export function windowResizeCallback() |
|
1594
|
|
|
{ |
|
1595
|
|
|
windowResize(); |
|
1596
|
|
|
} |
|
1597
|
|
|
|
|
1598
|
|
|
let substr = window.String.substr; |
|
1599
|
|
|
if ('b' !== 'ab'.substr(-1)) |
|
1600
|
|
|
{ |
|
1601
|
|
|
substr = (str, start, length) => { |
|
1602
|
|
|
start = 0 > start ? str.length + start : start; |
|
1603
|
|
|
return str.substr(start, length); |
|
1604
|
|
|
}; |
|
1605
|
|
|
|
|
1606
|
|
|
window.String.substr = substr; |
|
1607
|
|
|
} |
|
1608
|
|
|
|